package com.example.moduledemo;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.example.javalib.MyClass;
import com.example.myandroidlibrary.AndroidSystemHelper;

/**
 * @author wdl
 */
public class MainActivity extends AppCompatActivity implements View.OnClickListener {

    /**
     * 显示Java Module和Android Module调用方法后传回来的信息
     */
    private TextView tvShow;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Button btnDateTime = findViewById(R.id.btn_show_date_time);
        Button btnSystemInformation = findViewById(R.id.btn_show_system_information);
        tvShow = findViewById(R.id.tv_show);
        btnDateTime.setOnClickListener(this);
        btnSystemInformation.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.btn_show_date_time:
                String dateString = MyClass.getNowDateString();
                tvShow.setText(dateString);
                break;
            case R.id.btn_show_system_information:
                //访问本应用Android Module中的类
                String androidId = AndroidSystemHelper.getAndroidId(this);
                int cpuCore = AndroidSystemHelper.getNumCores();
                long memory = AndroidSystemHelper.getTotalMemory();

                String info = String.format("Android ID:%1$s\nCPU核数：%2$d\n总内存：%3$d KB", androidId, cpuCore, memory);
                tvShow.setText(info);
                break;
            default:
        }
    }
}
